跟上章節的Box相比較,Discrete是離散的資料類別
import numpy as np
from .space import Space
類別初始化
def __init__(self, n):
assert n >= 0
self.n = n
super(Discrete, self).__init__((), np.int64)
def sample(self):
return self.np_random.randint(self.n)
def contains(self, x):
if isinstance(x, int):
as_int = x
elif isinstance(x, (np.generic, np.ndarray)) and (x.dtype.kind in np.typecodes['AllInteger'] and x.shape == ()):
as_int = int(x)
else:
return False
return as_int >= 0 and as_int < self.n
對於動作控制來說,打電動很適合用Discrete設計,但像是轉方向盤,轉幾度這就要靠Box。其實基本的資料類別就這樣,明天來講講怎麼註冊寫好的自定義環境。
OpenAI gym 源碼:https://bre.is/WhrzVNKC